import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth'

// create an axios instance
const service = axios.create({
  baseURL: 'http://localhost:8080', // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

service.interceptors.request.use(
  config => {
    var token = localStorage.getItem("token");
    // config.headers = "Authorization:" + token;
    if (config && config.headers) { 
      config.headers['token']=token
    }
     return config;
  }
)

// response interceptor
service.interceptors.response.use(
  response => {
     if (response.data.code == 401) {
         //sessionStorage.setItem("lastPage", "goodList.html");
         alert(response.data.msg);
        //  location.href = "/login";
     }
     return response.data;
  }
)

export default service
